package com.proton.carepatchtemp.utils.ble;

import com.apkfuns.logutils.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Api on 2016/10/10.
 */

public class BlueDataProvider {

    private static final int DATA_SPLICE = 256;  //存放temp值
    private static final int DATA_SIZE = 1024;    //每次处理的波段
    public static List<Float> ecgSourceData = new ArrayList<>();  //ECG的元数据保存
    public static List<Float> ecgDataed = new ArrayList<>();  //处理过后的数据
    private static int index = 0;  //第几组数据索引

    public static void deallAllEcgSourceData() {
        //LogUtils.e(ecgSourceData.size());
        List<Float> tempList = new ArrayList<>();
        tempList.addAll(ecgSourceData);
        if (tempList.size() < (DATA_SIZE + DATA_SPLICE)) {
            return;
        }
        int rownum = (int) Math.floor((tempList.size() - (DATA_SIZE + DATA_SPLICE)) / DATA_SIZE);  //去除第一组数据之后BUFFER_SIZE长度的个数
        //LogUtils.e(rownum);
        //LogUtils.e(index);
        if (index == 0) {
            index++;
            double[] waitdeal = BlueUtils.getFirstDataFromList(tempList, DATA_SIZE + DATA_SPLICE);

//            ecgDataed.addAll(waitdeal);
//            double[] firdata1$4=GetQuarterData(firdata);
//            EcgRealTimeView.addEcgData(BlueDataDealWithJni.transDoubleArrToListFloat(firdata1$4));  //添加到自定义View进行绘制
            //EcgRealTimeView.addEcgData(BlueUtils.transDoubleArrToListFloat(waitdeal));
        } else if (rownum == index) {
            LogUtils.e("rownum==index is called");
            index++;
            double[] waitdeal = BlueUtils.getDataFromList(tempList, DATA_SIZE + DATA_SPLICE + DATA_SIZE * (rownum - 1), DATA_SIZE);  //获取取待处理的值
//            double[] otrdata=BlueDataDealWithJni.getArrayFromArray(BlueDataDealWithJni.get().getFilteredData(waitdeal));  //完成滤波操作
//            ecgDataed.addAll(BlueDataDealWithJni.transDoubleArrToListFloat(otrdata));
            /**
             * 绘制全部点
             * */
            //EcgRealTimeView.addEcgData(BlueDataDealWithJni.transDoubleArrToListFloat(otrdata));
            /**
             * 绘制1/4点
             * */
//            double[] otrdata1$4=GetQuarterData(otrdata);
//            //LogUtils.e(otrdata1$4);
//            EcgRealTimeView.addEcgData(BlueDataDealWithJni.transDoubleArrToListFloat(otrdata1$4));  //添加到自定义View进行绘制
            /**
             * 不进行滤波
             * */
            //EcgRealTimeView.addEcgData(BlueUtils.transDoubleArrToListFloat(waitdeal));
        }
    }

    public static double[] GetQuarterData(double[] ddd) {
        double[] dd = new double[ddd.length / 4];
        for (int i = 0; i < dd.length; i++) {
            dd[i] = ddd[i * 4];
        }
        return dd;
    }

}

